package com.hnqcgczy.controller;

import com.hnqcgczy.service.IOrderService;
import com.hnqcgczy.service.impl.OrderServiceImpl;
import com.hnqcgczy.vo.TOrder;

import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

@WebServlet("/myorder")
public class MyOrderSerlvet extends BaseServlet {
    @Override
    public String home(HttpServletRequest req, HttpServletResponse resp) {
        //登陆校验
        String tuId=(String)req.getSession().getAttribute("tuId");
        //判断如果tuId为null，跳转登陆
        if(tuId==null){

            return "r:login.jsp";
        }

        //订单业务
        IOrderService orderService=new OrderServiceImpl();
        //订单列表
        List<TOrder> orderList=orderService.getOrderList(tuId);
        //存储在request作用域
        req.setAttribute("orderList",orderList);
        //转发到我的订单jsp /order.jsp
       return "f:order";
    }

    public String updateOrder(HttpServletRequest req, HttpServletResponse resp) {

        String orderid=req.getParameter("orderid");
        String status=req.getParameter("status");
        //订单业务
        IOrderService orderService=new OrderServiceImpl();
        TOrder order=orderService.getOrder(orderid);
        if(order!=null){
            //状态修改为已支付
            order.setToStatus(Integer.parseInt(status));
            orderService.updateOrder(order);
        }
        //转发到我的订单jsp /order.jsp
        return "r:myorder";
    }
}
